//
//  EveryDayTeHuiCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/18.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "EveryDayTeHuiCell.h"
#import "EveryTeHuiItemCell.h"
#import "GoodDetailController.h"

@interface EveryDayTeHuiCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (weak, nonatomic) IBOutlet UIImageView *topImageView;


@end

@implementation EveryDayTeHuiCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.topImageView.layer.masksToBounds = YES;
    self.topImageView.layer.cornerRadius = 36;
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    self.bottomMargin.constant = 0;
    [self.myCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([EveryTeHuiItemCell class]) bundle:nil]forCellWithReuseIdentifier:[EveryTeHuiItemCell identifierStr]];
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    self.myCollectionView.backgroundColor = [UIColor whiteColor];
    
//    self.myCollectionView.pagingEnabled = YES;
    
    
}


- (void)setModel:(MarketHomeModel *)model{
    _model = model;
    
//    [self.topImageView sd_setImageWithURL:[NSURL URLWithString:@"http://pic39.nipic.com/20140311/10600816_135850674000_2.jpg"] placeholderImage:nil];

    
    [self.myCollectionView reloadData];
    
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    if (self.model == nil) {
        return 0;
    } else {
        return 1;
    }
    

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (self.model == nil) {
        return 0;
    } else {
        return self.model.tehui.count;
    }
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    EveryTeHuiItemCell *temp = (EveryTeHuiItemCell *)[collectionView dequeueReusableCellWithReuseIdentifier:[EveryTeHuiItemCell identifierStr] forIndexPath:indexPath];
    
    //    temp.contentView.backgroundColor = randomColor;
    
    temp.subModel = self.model.tehui[indexPath.item];
    
    return temp;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    GoodDetailController *tempVC = [[GoodDetailController alloc]init];
    
    MarketHSubModel *subModel = self.model.tehui[indexPath.item];
    
    OneGoodsModel *tempModel = [[OneGoodsModel alloc]init];
    
    tempModel.goods_id = subModel.goods_id;
    
    tempModel.goods_image_url = subModel.pic_cover_small;
    
    tempVC.goodsModel = tempModel;
    
    [self.viewController.navigationController pushViewController:tempVC animated:YES];
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
